﻿using System;
namespace YanZhiwei.DotNet2.Utilities.Common
{
    /// <summary>
    /// IComparerHelper帮助类
    /// </summary>
    public class IComparerHelper
    {
        #region IComparer接口实现内，Comparer方法判断帮助
        /// <summary>
        ///IComparer接口实现内，Comparer方法判断帮助
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="x">泛型x值</param>
        /// <param name="y">泛型y值</param>
        /// <param name="comparedelete">委托；eg:(t, u) => { return t.PoleID.CompareTo(u.PoleID); }</param>
        /// <returns>对象比较</returns>
        public static int ComparePlus<T>(T x, T y, Func<T, T, int> comparedelete)
        {
            if (x == null)
            {
                if (y == null)
                    return 0;
                return -1;
            }
            if (y == null)
                return 1;
            if (x.Equals(y))
                return 0;
            return comparedelete(x, y);
        }
        #endregion 
    }
}